package cn.jlonely.xyhx.admin.mapper;

import cn.jlonely.xyhx.pojo.Ranking;
import cn.jlonely.xyhx.pojo.vo.CommentPageVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RankingMapper {

    @Select("SELECT * FROM ranking_table WHERE topic LIKE CONCAT('%', #{topic}, '%') or ranking_id=#{id}")
    @Results({
            @Result(property = "id", column = "ranking_id")
    })
    List<Ranking> getRankingInfoAll(String topic, Integer id);

    @Insert("INSERT INTO ranking_table ( topic, cover_image, start_time, end_time, introduce) " +
            "VALUES ( #{topic}, #{coverImage}, #{startTime}, #{endTime}, #{introduce})")
    void createRanking(Ranking ranking);

    @Delete("DELETE FROM ranking_table WHERE ranking_id = #{id}")
    void deleteRanking(Integer id);

    @Update("UPDATE ranking_table SET topic = #{topic}, cover_image = #{coverImage}, start_time = #{startTime}, " +
            "end_time = #{endTime}, introduce = #{introduce} WHERE ranking_id = #{id}")
    void updateRanking(Ranking ranking);

    /**
     * 获取评论
     * @return
     */
    List<CommentPageVo> getCommentsAll();

    /**
     * 修改评论状态
     * @param commentId
     * @param status
     */
    @Update("UPDATE comments SET status = #{status} WHERE comment_id = #{commentId}")
    void updateCommentsStatus(Integer commentId, Integer status);

    /**
     * 删除评论
     * @param commentId
     */
    @Delete("DELETE FROM comments WHERE comment_id = #{commentId}")
    void deleteComments(Integer commentId);
}
